class Solution {
public:
    int temperatureTrend(vector<int>& A, vector<int>& B)
    {
        int ans = 0;
        int n = A.size();
        vector<int> At(n - 1);
        vector<int> Bt(n - 1);
        for (int i = 0; i < n - 1; i++)
        {
            if (A[i + 1] > A[i]) At[i] = 0;
            else if (A[i + 1] == A[i]) At[i] = 1;
            else At[i] = 2;

            if (B[i + 1] > B[i]) Bt[i] = 0;
            else if (B[i + 1] == B[i]) Bt[i] = 1;
            else Bt[i] = 2;
        }

        int l = 0;
        int r = 0;
        while (r < n - 1)
        {
            if (At[r] != Bt[r]) l = ++r;
            else ans = max(ans, r - l + 1), r++;
        }
        return ans;
    }
};